procedure GenerateContents(var Str: String); const IniFile = '.\report.ini'; procedure DataSetTable(DataSet: TDataSet; NewRec: Boolean); { NEW RECORD - Actions: POST, CANCEL } { BROWSE RECORD - Actions: FIRST, PREV, NEXT, LAST, INSERT, DELETE, REFRESH } const Int: Array[1..9] of Char = '123456789'; var i,j,col,items: Integer; option: ShortString; begin {$IFDEF DEBUG} Str := Str + '

'; Str := Str + 'Debug Action: '#13#10; Str := Str + '

'; {$ENDIF} if NewRec then begin Str := Str + ''#13#10; Str := Str + ''#13#10 end else begin Str := Str + ''#13#10; Str := Str + ''#13#10; Str := Str + ''#13#10; Str := Str + ''#13#10; Str := Str + ' '#13#10; Str := Str + ''#13#10; Str := Str + ''#13#10; Str := Str + ' '#13#10; Str := Str + ''#13#10; Str := Str + ''#13#10; Str := Str + ' '#13#10; Str := Str + ''#13#10; end; Str := Str + ''#13#10; Str := Str + '

'#13#10; with DataSet do begin if NewRec then Str := Str + ''#13#10 else Str := Str + ''#13#10; Str := Str + ''#13#10; col := 0; with TIniFile.Create(IniFile) do try for i:=1 to FieldCount-1 do { first field was hidden } begin if Fields[i].DataType = ftMemo then begin Str := Str + ''; col := 2 end; Str := Str + ''#13#10''; col := 1 end; Str := Str + '' end; Str := Str + ''#13#10 finally Str := Str + '
'; col := 3; end else if Fields[i].Size > 99 then begin Inc(col,2); if col > 3 then begin Str := Str + '
' end else begin Inc(col); if col > 3 then begin Str := Str + '
' end; Str := Str + ''+ReadString(Fields[i].FieldName,'Name',Fields[i].FieldName)+'
'; items := ReadInteger(Fields[i].FieldName,'Items',0); if items = 0 then begin if Fields[i].DataType = ftMemo then begin Str := Str + '' end else begin if Fields[i].Size > 99 then Str := Str + '' end end else begin Str := Str + '' end; Str := Str + '
'#13#10; Free end end end; const _DatabaseName = ''; { no alias: current directory } _TableName = 'report.db'; Action: String[7] = ''; var Table: TTable; Session: TSession; { IMPORTANT } Report,i: Integer; { key field } NoChange: Boolean; begin Str := ''; Action := ''; ShortDateFormat := 'DD/MM/YYYY'; GetDir(0,Str); if IOResult <> 0 then { skip }; Str := Str + ''#13#10; with TIniFile.Create(IniFile) do try Str := Str + ''#13#10; Str := Str + ''+ReadString(_TableName,'Name','')+''#13#10; Str := Str + ''#13#10; Str := Str + ''#13#10; Str := Str + '

'#13#10; Str := Str + '

'; Str := Str + ''; Str := Str + ReadString(_TableName,'Name',''); Str := Str + '

'#13#10; Str := Str + '
'#13#10 finally Free end; // IMPORTANT Session := TSession.Create(nil); Session.AutosessionName := True; Session.Active := True; // IMPORTANT Table := TTable.Create(nil); Table.SessionName := Session.SessionName; with Table do try Active := False; TableType := ttParadox; { DatabaseName := _DatabaseName; } TableName := _TableName; Open; First; { locate current record } Report := ValueAsInteger('Report'); if Report > 0 then FindKey([Report]) else First; { update record if data has changed } NoChange := True; { assume no change } if (Value('_'+Fields[0].FieldName) <> '') and { old data is stored } (ValueAsInteger(Fields[0].FieldName) <> -1) then begin NoChange := True; { assume no change } for i:=0 to FieldCount-1 do NoChange := NoChange AND (Value('_'+Fields[i].FieldName) = Value(Fields[i].FieldName)); if not NoChange then { update record } begin { check if data in table is still the same } NoChange := True; for i:=0 to FieldCount-1 do NoChange := NoChange AND (Value('_'+Fields[i].FieldName) = Fields[i].AsString); if not NoChange then { table changed!! } begin Str := Str + 'Error: value of record changed before your update was made!'; Action := 'Refresh' { force refresh } end else { go ahead! } begin Str := Str + 'Note: '; Edit; { set Table in Edit-mode } for i:=0 to FieldCount-1 do begin if (Value('_'+Fields[i].FieldName) <> Value(Fields[i].FieldName)) then begin {$IFDEF DEBUG} Str := Str + IntToStr(i)+' ['+Value('_'+Fields[i].FieldName)+']-{'+Value(Fields[i].FieldName)+'} '; {$ENDIF} Fields[i].AsString := Value(Fields[i].FieldName) { new } end end; Post { Post data in Table }; Str := Str + ' previous record updated in table

'#13#10 end end end; { determine action } if Action = '' then Action := Value('Action'); if Action = '' then Action := 'First'; { perform action } if Action = 'First' then First else if Action = 'Next' then Next else if Action = 'Prev' then Prior else if Action = 'Last' then Last else if (Action = 'Find') or (Action = 'Query') then begin // TODO: special query CGI-Form end else if Action = 'Delete' then Delete else if Action = 'Insert' then { skip } else if Action = 'Post' then { insert record } begin First; Report := 0; while not Eof do begin if Fields[0].AsInteger > Report then Report := Fields[0].AsInteger; Next end; Inc(Report); Insert; Fields[0].AsInteger := Report; for i:=1 to FieldCount-1 do Fields[i].AsString := Value(Fields[i].FieldName); Post end else if Action = 'Cancel' then { cancel } else { Refresh }; Str := Str + '

' + Action + '

'; for i:=0 to FieldCount-1 do Str := Str + ''#13#10; Str := Str + Fields[0].AsString+' - '+IntToStr(RecNo)+ '/'+IntToStr(RecordCount)+'  '#13#10; { generate HTML CGI-Form with fields } DataSetTable(Table,Action = 'Insert'); Close finally Str := Str + '

'#13#10; Str := Str + ''#13#10; Str := Str + ''#13#10; Free end; // IMPORTANT Session.Free; Session := nil; // IMPORTANT Table := nil end;